# 【练习】阶乘

# 循环实现
n = int(input("请输入一个数字："))
def fact_x(n):
    if n == 0:
        print("结果为:", 1)
    else:
        num = 1
        for i in range(1, n + 1):
            num = num * i
        print(f"结果为：{num}")


fact_x(n)


def test_fact_x():
    assert fact_x(3) == 6
    assert fact_x(5) == 120


# 递归实现'
n = int(input("请输入一个数字："))
def fact_d(n):
    if n == 0 or n == 1:
        return 1
    else:
        result = fact_d(n - 1) * n
        return result
print(f"结果为：{fact_d(n)}")


def test_fact_d():
    assert fact_d(5)==120
